<template>
<!-- 节假日定义 -->
  <div style="padding:20px">
    <div slot="operation" class="Head_Top">
      <div class="Top_one">
        <el-button @click="addgroup" type="primary"
          >新增</el-button>
      </div>
      <div class="Top_two">
        <div class="Top_two_radio">
          <el-checkbox v-model="checked">已停用</el-checkbox>
        </div>
        <div class="Top_two_one">
          <el-input placeholder="请输入内容" v-model="listfrom.KeyWord">
            <i
              slot="suffix"
              @click="getlistdata"
              class="el-input__icon el-icon-search"
            ></i>
          </el-input>
        </div>
        <div class="Top_two_two1">
          <el-button
            icon="el-icon-refresh"
            size="small"
            class="refresh"
            @click="getlistdata"
          ></el-button>
          <!-- <i class="iconfont icon-shuaxin" @click="Toreload"></i> -->
        </div>
      </div>
      <!-- <el-button @click="modal12 = true" type="primary">点击编辑</el-button> -->
    </div>
    <div slot="table">
      <table-cmp
        style="width:100%"
        class="table_cmp"
        :loading="loading"
        :table-data="tableData"
        :table-label="tableLabel"
        @handleButton="handleButton"
        @rowClick="rowClick"
        @cellClick="cellClick"
        @handleSortChange="handleSortChange"
        @handleSelectionChange="handleSelectionChange"
      ></table-cmp>
      <div style="text-align: right;">
        <el-pagination
          v-if="tatolpage > 10"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="listfrom.PageIndex"
          layout=" prev, pager, next"
          :total="tatolpage"
        >
        </el-pagination>
      </div>
    </div>
    <holiday ref="holiday"></holiday>
  </div>
</template>

<script>
var occupancyDisplay = {
  template: `<div>
            <el-button type="text" @click='start(row)' v-if="row.Status==3" size="small">启用</el-button>
            <el-button type="text" @click='stop(row)' v-if="row.Status==2" size="small">停用</el-button>
            <el-button type="text" @click='remove(row)' v-if="row.Status==3" size="small">删除</el-button>
            <el-button type="text" @click='editDetail(row)' size="small">编辑</el-button>
  
  </div>`,
  props: ['row'],
  created() {
  },
  methods: {
    start(row) {
      let obj = {
            "MN": "UnCancelHoliday",
            "RequestId": 1,
            "UserId": 1,
            "DataContent": {
              "Ids":row.Id
            }
          }
          this.MIX_send(obj);
    },
    stop(row) {
      let obj = {
            "MN": "CancelHoliday",
            "RequestId": 1,
            "UserId": 1,
            "DataContent": {
              "Ids":row.Id
            }
          }
          this.MIX_send(obj);
    },
    remove(row) {
      this.$confirm('此操作将删除该条信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          // this.$message({
          //   type: 'success',
          //   message: '删除成功!'
          // });
          let obj = {
            "MN": "RemoveHoliday",
            "RequestId": 1,
            "UserId": 1,
            "DataContent": {
              "Ids":row.Id
            }
          }
          this.MIX_send(obj);
        }).catch(() => {         
        });
    },
    editDetail(row) {
      this.$emit('edit-detail', row);
      // console.log(this.row,'1111111');

    }
  }
};
var that
import holiday from "./dialog/holiday";
export default {
  name: "",
  data() {
    return {
      modal12: false,
      loading: false,
      checked: true,
      tatolpage: 0,
      tableData: [],
      listfrom: {
        "KeyWord": '',
        "IsStop": '',
        "PageSize": 10,
        "PageIndex": 1
      },
      tableLabel: [
        { label: '状态', param: 'Status', width: '100', align: 'center', sortable: false, render: (row) => {
            if (row.Status == 0) {
              return '草稿'
            } else if (row.Status == 1) {
              return '待审批'
            } else if (row.Status == 2) {
              return '启用'
            } else if (row.Status == 3) {
              return '停用'
            }
          }
        },
        { label: '节假日名称', param: 'Name', align: 'center', width: '200', sortable: false },
        { label: '数据来源', param: 'Resoures', align: 'center', width: '80',render:(row)=>{
          if (row.Resoures =='1') {
            return '人工登记'
          }
        }},
        { label: '类型', param: 'Type', align: 'center', width: '80',render:(row)=>{
          if (row.Type=='1') {
            return '每年固定'
          }
          if (row.Type=='2') {
            return '每年变化'
          }
        }},
        { label: '年度', param: 'Year', align: 'center', width: '80',},
        { label: '开始日期', param: 'StartDate', align: 'center', width: '150',},
        { label: '结束日期', param: 'EndDate', align: 'center', width: '150',},
        { label: '描述', param: 'Desc', align: 'center' },
        { label: '操作', align: 'center', width: '300',
          component: occupancyDisplay, listeners: {
            'edit-detail'(row) {
              that.editdetail(row);
            },
          }
        }
      ],
      fromData: {},
      columns: [],
    };
  },
  components: {
    holiday
  },
  watch: {
    "$store.state.Purchasingmanagement.MNvalue.GetUsers": function (data) {
      this.tatolpage = data.ReturnData.DataCount;
      this.tableData = data.ReturnData.Data;
    },
    "$store.state.Humanmanage.QueryHoliday": function (data) {
      let DataContent = data.ReturnData.DataCount;
      this.tableData = data.ReturnData.Data;
    },
    "$store.state.Humanmanage.UnCancelHoliday": function (data) {
      this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.getlistdata();
    },
    "$store.state.Humanmanage.CancelHoliday": function (data) {
      this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.getlistdata();
    },
    "$store.state.Humanmanage.RemoveHoliday": function (data) {
      this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.getlistdata();
    },
    "$store.state.Humanmanage.UnCancelShift": function (data) {
      this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.getlistdata();
    },
    "checked": function (data) {
        this.getlistdata();
    },
  },
  methods: {
    // 添加组
    addgroup() {
      this.$refs.holiday.formtype = 1;
      this.$refs.holiday.dialogFormVisible = true;
    },
    editdetail(row){
      let rowdata = JSON.parse(JSON.stringify(row));
      this.$refs.holiday.formtype = 2;
      this.$refs.holiday.value6 = [rowdata.StartDate,rowdata.EndDate];
      this.$refs.holiday.form = rowdata;
      this.$refs.holiday.dialogFormVisible = true;

    },
    getlistdata() {
       if (this.checked) {
        this.listfrom.IsStop = 0;
      } else{
        this.listfrom.IsStop = 1;
      }
      let obj = {
        "MN": "QueryHoliday",
        "RequestId": 1,
        "UserId": 1,
        "DataContent": this.listfrom
      }
      this.MIX_send(obj);
    },
    rowClick(data) { },
    handleCurrentChange(data) {
      this.listfrom.PageIndex = data;
      this.getlistdata();
    },
    handleSizeChange(data) {
      // console.log(data,'handleSizeChange');
      this.listfrom.PageSize = data;
      this.getlistdata();
    },
    handleButton(data) { },
    cellClick(data) { },
    handleSortChange(data) { },
    handleSelectionChange(data) { },
    GetTableId(data) {
      console.log(data);
    },
    Toreload() {
      this.listfrom = {
        "Status": '',
        "KeyWord": '',
        "Status": '',
        "PageSize": 10,
        "PageIndex": 1
      }
      this.getlistdata();
    },
    search() {
      this.getlistdata();
    },
    // 表格上方筛选slot的事件回调
    add() {
      console.log("表格上方筛选slot的事件回调");
    },
    // 弹出框表单提交
    Commit() {
      // console.log(this.$refs.PopForm.value);
    },
    // 弹出框底部标签页组件事件的回调
    edit(val) {
      console.log(val);
    }
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    that = this;
    this.getlistdata();
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() { }
}
</script>

<style lang='less' scoped>
.Head_Top {
  width: 100%;
  height: 51px;
  // overflow: hidden;
  display: flex;
  justify-content: space-between;
  .Top_one {
    width: 350px;
  }
  .Top_two {
    // flex: 1;
    display: flex;
    .Top_two_two {
      padding: 10px;
    }
  }
  .Top_three {
    width: 50px;
  }
}
</style>